﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns:x="urn:schemas-microsoft-com:office:excel">
<link href="../style/adminStyle.css" rel="stylesheet" type="text/css" />
<style>
html, body {
	width: 100%;
	height: 100%;
}

#txt {
	
	text-align: center;
	color: #9D9D9D;
	min-height: 3%;
	border: 1px solid #8E8E8E;
}
#ex{
font-size:1.2em;

}
#txt:hover {
	background-color: #7B7B7B;
}
</style>
<script type="text/javascript">  
var idTmr;
function  getExplorer() {
    var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
    var isOpera = userAgent.indexOf("Opera") > -1; //判断是否Opera浏览器
    var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera; //判断是否IE浏览器
    var isEdge = userAgent.indexOf("Windows NT 6.1; Trident/7.0;") > -1 && !isIE; //判断是否IE的Edge浏览器
    var isFF = userAgent.indexOf("Firefox") > -1; //判断是否Firefox浏览器
    var isSafari = userAgent.indexOf("Safari") > -1 && userAgent.indexOf("Chrome") == -1; //判断是否Safari浏览器
    var isChrome = userAgent.indexOf("Chrome") > -1 && userAgent.indexOf("Safari") > -1; //判断Chrome浏览器

    //ie
    if (isIE || !!window.ActiveXObject || "ActiveXObject" in window) {
        return 'ie';
    }
    //firefox
    else if (isFF) {
        return 'Firefox';
    }
    //Chrome
    else if(isChrome){
        return 'Chrome';
    }
    //Opera
    else if(isOpera){
        return 'Opera';
    }
    //Safari
    else if(isSafari){
        return 'Safari';
    }
}
function export_excel(tableid) {
    if(getExplorer()=='ie'){
        var curTbl = document.getElementById(tableid);
        var oXL;
        try {
            oXL = new ActiveXObject("Excel.Application"); //创建AX对象excel
        } catch (e) {
            alert("无法启动Excel!\n\n如果您确信您的电脑中已经安装了Excel，" + "那么请调整IE的安全级别。\n\n具体操作：\n\n" + "工具 → Internet选项 → 安全 → 自定义级别 → 对没有标记为安全的ActiveX进行初始化和脚本运行 → 启用");
            return false;
        }

        var oWB = oXL.Workbooks.Add();
        var oSheet = oWB.ActiveSheet;
        var Lenr = curTbl.rows.length;
        for (i = 0; i < Lenr; i++) {
            var Lenc = curTbl.rows(i).cells.length;
            for (j = 0; j < Lenc; j++) {
                oSheet.Cells(i + 1, j + 1).value = curTbl.rows(i).cells(j).innerText;
            }
        }
        oXL.Visible = true;

        //导出剪切板上的数据为excel
//        var curTbl = document.getElementById(tableid);
//        var oXL = new ActiveXObject("Excel.Application"); //创建AX对象excel
//        var oWB = oXL.Workbooks.Add();
//        var xlsheet = oWB.Worksheets(1);
//        var sel = document.body.createTextRange();
//        sel.moveToElementText(curTbl);
//        sel.collapse(true);
//        sel.select();
//        sel.execCommand("Copy");
//        xlsheet.Paste();
//        oXL.Visible = true;
//
//        try {
//            var fname = oXL.Application.GetSaveAsFilename("Excel.xls", "Excel Spreadsheets (*.xls), *.xls");
//        } catch (e) {
//            console.log("Nested catch caught " + e);
//        } finally {
//            oWB.SaveAs(fname);
//            oWB.Close(savechanges = false);
//            oXL.Quit();
//            oXL = null;
//            idTmr = window.setInterval("Cleanup();", 1);
//        }
    }else{
        tableToExcel(tableid)
    }
}
function Cleanup() {
    window.clearInterval(idTmr);
    CollectGarbage();
}

var tableToExcel = (function() {
    var uri = 'data:application/vnd.ms-excel;base64,',
    template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>',
    base64 = function(s) {
        return window.btoa(unescape(encodeURIComponent(s)))
    },
    // 下面这段函数作用是：将template中的变量替换为页面内容ctx获取到的值
    format = function(s, c) {
        return s.replace(/{(\w+)}/g,
            function(m, p) {
                return c[p];
            }
        )
    };
    return function(table, name) {
        if (!table.nodeType) {
            table = document.getElementById(table)
        }
        // 获取表单的名字和表单查询的内容
        var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML};
        // format()函数：通过格式操作使任意类型的数据转换成一个字符串
        // base64()：进行编码
        window.location.href = uri + base64(format(template, ctx))
    }
})()

</script>
<head>


<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>数据下载</title>
</head>
<body>
	<div class="wrap start-page">

		<div id="myDiv">
			<table id="tableExcel" width="100%" border="1" cellspacing="0"
				cellpadding="0">
				<thead>
					<tr>
						<td>待支付订单</td>
						<td>已支付订单</td>
						<td>已交易金额</td>
						<td>待交易金额</td>
						<td>大师总人数</td>
						<td>已支付预约人数</td>
						<td>待支付预约人数</td>
						
					</tr>
					<tr>
						<td>${main.orderNo}</td>
						<td>${main.orderYes}</td>
						<td>${main.sumYes}</td>
						<td>${main.sumNo}</td>
						<td>${main.dScount}</td>
						<td>${main.dScountYes}</td>
						<td>${main.dScountNo}</td>
					</tr>
					
					
					
					<tr>
						
						<td>Android用户</td>
						<td>IOS用户</td>
						<td>总用户量</td>
						<td>日活跃量</td>
						<td>周活跃量</td>
						<td>月活跃量</td>
						<td>看点总数量</td>
					</tr>
					
					<tr>
						<td>${main.adcount}</td>
						<td>${main.IOScount}</td>
						<td>${main.ISandDcont}</td>
						<td>${main.yer}</td>
						<td>${main.week}</td>
						<td>${main.month}</td>
						<td>${main.newscount}</td>
					</tr>
					
					<tr>
						
						<td>日活跃量</td>
						<td>周活跃量</td>
						<td>月活跃量</td>
						<td>暂无</td>
						<td>暂无</td>
						<td>暂无</td>
						<td>暂无</td>
					</tr>
					
					<tr>
						<td>${main.ldays}%</td>
						<td>${main.lweeks}%</td>
						<td>${main.lmonths}%</td>
						<td>0</td>
						<td>0</td>
						<td>0</td>
						<td>0</td>
					</tr>
					
					<tr>
						
						<td>充值成功数量</td>
						<td>流年运势使用量</td>
						<td>爱情婚姻使用量</td>
						<td>财运测算使用量</td>
						<td>健康测算使用量</td>
						<td>事业测算使用量</td>
						<td>功名测算使用量</td>
					</tr>
					
					
					<tr>
						<td>${main.czcount}</td>
						<td>${main.lncount}</td>
						<td>${main.aqcount}</td>
						<td>${main.cycount}</td>
						<td>${main.jkcount}</td>
						<td>${main.sycount}</td>
						<td>${main.gmcount}</td>
					</tr>
					
						<tr>
						
						<td>性格测算使用量</td>
						<td>周公解梦使用量</td>
						<td>塔罗牌使用量</td>
						<td>起名改名使用量</td>
						<td>紫薇斗数使用量</td>
						<td>公司测名使用量</td>
						<td>大师预约使用量</td>
					</tr>
					
					
					<tr>
						<td>${main.xgcount}</td>
						<td>${main.zgcount}</td>
						<td>${main.tlpcount}</td>
						<td>${main.qmcount}</td>
						<td>${main.zwcount}</td>
						<td>${main.gscount}</td>
						<td>${main.dScountYes}</td>
					</tr>
					
				</thead>
				<tbody></tbody>
			</table>
		</div>

		<div class="l-button" onclick="export_excel('tableExcel')" id="txt" style="cursor:pointer">
			<span id="ex">导出Excel</span>
			</div>

	</div>

</body>
</html>
